package screens 
{
	import org.flixel.FlxButton;
	import org.flixel.FlxG;
	import org.flixel.FlxSprite
	import org.flixel.FlxState;
	import org.flixel.FlxText;
	//import org.flixel.plugin.photonstorm.FlxButtonPlus;
	
	import tools.MyFlxSprite;
	import tools.ButtonFactory;
	import tools.SaveManager;
	
	public class GameOver extends FlxState
	{
		
		public function GameOver() {
		}
		
		override public function create():void {
			super.create();
			
			if (!Registry.gameInfos.template.logo) {
				var mainTitle_txt:FlxText = new FlxText(10, 20, FlxG.width, Registry.gameName);
				mainTitle_txt.color = FlxG.WHITE;
				mainTitle_txt.size = 60;
				mainTitle_txt.shadow = 0xffaaaaaa;
				add(mainTitle_txt);
			} else {
				var header:MyFlxSprite = new MyFlxSprite(0,0);
				header.loadGraphicWithBitmap(Registry.gameInfos.template.logo);
				add(header);
			}
			
			var subTitle_txt:FlxText = new FlxText(10, 200, FlxG.width, "GAME OVER");
			subTitle_txt.alignment = "center";
			subTitle_txt.size = 15;
			add(subTitle_txt);
			
			var score:FlxText = new FlxText(300, 230, FlxG.width, "SCORE : " + Registry.player.score + "\nLEVEL : " + Registry.player.level);
			score.size = 21;
			add(score);
			
			var param:Array = [];
			
			if(Registry.player && Registry.player.infos.gamePlay.lives > 0)  param.push({'label' : 'NIVEAU SUIVANT',	 'callBack' : startGame});
			param.push({'label' : 'Charger', 'callBack' :  displayChoice});
			if(Registry.player && Registry.player.infos.gamePlay.lives > 0) param.push({'label' : 'Sauvegarder', 'callBack' : SaveManager.saveGame});
			param.push({'label' : 'Quitter', 'callBack' : returnHome});
			
			var buttons:ButtonFactory = new ButtonFactory(param, null, 300, Registry.gameInfos.template);
			add(buttons);
			
			//showpausemenu
			FlxG.mouse.show();
		}
		
		
		private function displayChoice(label:String=null):void{
			var saves:Object = SaveManager.getSaves();
			var param:Array = [];
			
			for (var key:String in saves){
				param.push({'label' : key,  'callBack' : SaveManager.loadGame});
			}
			param.push({'label' : 'Effacer les sauvegardes',  'callBack' : SaveManager.clearAllGames});
			
			add((new FlxSprite(480,220)).makeGraphic(190, 30 * (param.length + 1), 0x55000000));
			var buttons:ButtonFactory = new ButtonFactory(param, 500, 230);
			add(buttons);
		}
		
		private function removeChoices(label:String=null):void{
			
		}
		
		
		private function startGame(label:String=null):void {
			Registry.erase();
			FlxG.switchState(new PlayState);
		}
		private function returnHome(label:String=null):void{ FlxG.switchState(new GameList); }
		
	}

}